package cn.yes.jdbc;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class AppJdbcSelect {
    public static void main(String[] args) throws Exception{
        //1加载驱动类
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:43306/test?useSSL=false";
        String username="root";
        String password="root";
        //3创建陈述对象
        Connection connection = DriverManager.getConnection(url, username, password);
        Statement statement = connection.createStatement();
        //4执行查询
        String sql="SELECT id,username FROM `user` ORDER BY id";
        ResultSet set = statement.executeQuery(sql);
        //获取数据
        //int []a = new int[3];
        //String []b= new String[3];
        //for(int i=0;i<3;i++) {
        //    set.next();
        //    a[i] = set.getInt(1);
        //    b[i] = set.getString(2);
        //}
        //for(int i=0;i<3;i++) {
        //    System.out.println(a[i]);
        //    System.out.println(b[i]);
        int i=0;
        while(i<3) {
            set.next();
            int id = set.getInt(1);
            String name = set.getString(2);
            System.out.println(id+"   "+name);
            i++;
        }

    }
    }

